package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.stark.more.MorePrefUtil;
import com.stark.more.MoreUiUtil;
import com.stark.more.about.DefAboutActivity;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.databinding.ActivityMyBinding;
import stark.common.basic.base.BaseWebviewActivity;
import stark.common.basic.event.EventStatProxy;

public class MyActivity extends BaseAc<ActivityMyBinding> {


    @Override
    protected int onCreate() {
        return R.layout.activity_my;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent5(this, mDataBinding.event5Container);
        mDataBinding.ivMyBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        mDataBinding.ivSettingsRecom.setOnClickListener(this);
        mDataBinding.llPrivacy.setOnClickListener(this);
        mDataBinding.llFeedback.setOnClickListener(this);
        mDataBinding.llAbout.setOnClickListener(this);
        mDataBinding.llAgreement.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.ivSettingsRecom:
                boolean isOpened = MoreUiUtil.isPersonalRecommendOpened();
                MoreUiUtil.setPersonalRecommendOpened(!isOpened);
                if (isOpened) {
                    mDataBinding.ivSettingsRecom.setImageResource(R.drawable.guan1);
                } else {
                    mDataBinding.ivSettingsRecom.setImageResource(R.drawable.kai1);
                }
                break;
            case R.id.llPrivacy://隐私政策
                BaseWebviewActivity.openAssetPrivacy(mContext);
                break;
            case R.id.llFeedback://意见反馈
                BaseWebviewActivity.openFeedback(mContext);
                break;
            case R.id.llAbout://关于我们
                startActivity(new Intent(mContext, DefAboutActivity.class));
                break;
            case R.id.llAgreement://用户协议
                BaseWebviewActivity.openAssetTerms(mContext);
                break;
        }
    }

    @Override
    protected void initData() {
        boolean isOpened = MoreUiUtil.isPersonalRecommendOpened();
        if (isOpened) {
            //将控件开关设为开
            mDataBinding.ivSettingsRecom.setImageResource(R.drawable.kai1);
        } else {
            //将控件开关设为关
            mDataBinding.ivSettingsRecom.setImageResource(R.drawable.guan1);
        }
        boolean showPersonalRecommend = MorePrefUtil.showPersonalRecommend();
        if (showPersonalRecommend) {
            //显示个性化开关控件
            mDataBinding.rlSettingsRecom.setVisibility(View.VISIBLE);
        } else {
            //隐藏个性化开关控件
            mDataBinding.rlSettingsRecom.setVisibility(View.GONE);
        }
    }
}